package com.qf.service.impl;

import com.qf.dao.GoodsMapper;
import com.qf.pojo.entity.Goods;
import com.qf.pojo.entity.GoodsClassify;
import com.qf.pojo.entity.StoreInfo;
import com.qf.pojo.resp.BaseResp;
import com.qf.pojo.resp.GoodsResp;
import com.qf.pojo.vo.GoodsClassifyVo2;
import com.qf.pojo.vo.GoodsVo;
import com.qf.pojo.vo.StoreInfoVo2;
import com.qf.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {
        @Autowired
        GoodsMapper goodsMapper;

    @Override
    public BaseResp findAll(Integer id) {

        List<GoodsClassifyVo2> allGoods = goodsMapper.findAllGoods(id);
        if (allGoods != null) {
         return    new BaseResp(200, "success", allGoods);
        }

        return new BaseResp().ERROR();
    }

    @Override
    public BaseResp updateOne(GoodsResp goodsResp) {
        System.out.println(goodsResp);
            if (goodsResp!=null && goodsResp.getId() > 0) {
                System.out.println("好了");

               goodsMapper.updateOne(goodsResp);

                goodsMapper.updateSys(goodsResp.getId(),goodsResp.getClassifysId());

                return new BaseResp(200, "success", null);
            }

        return new BaseResp().ERROR();
    }

    @Override
    public BaseResp allType(Integer id) {
      List<GoodsClassify> classifys =  goodsMapper.findAllType(id);
      if (classifys != null ) {
          return new BaseResp(200,"success",classifys);
      }
        return new BaseResp().ERROR();
    }

    @Override
    public BaseResp addOne(GoodsResp goodsResp) {
        System.out.println(goodsResp);
        if (goodsResp!=null&&goodsResp.getClassifysId()>0) {
            goodsMapper.addOne(goodsResp);
            goodsMapper.addType(goodsResp.getId(), goodsResp.getClassifysId());
            System.out.println(goodsResp);
            return  new BaseResp(200, "success", null);
        }
        return new BaseResp().ERROR();
    }

    @Override
    public BaseResp deleteOne(GoodsResp goodsResp) {
        System.out.println(goodsResp);
        if (goodsResp!=null && goodsResp.getId()>0) {
            goodsMapper.deleteOne(goodsResp.getId());
            goodsMapper.deleteType(goodsResp.getId(), goodsResp.getClassifysId());
            return  new BaseResp(200, "success", null);

        }

        return new BaseResp().ERROR();
    }
}
